Create Payment

In this guide, we will create a payment using the ApteanPay GraphQL Playground.

Headers Required for GraphQL API Playground

Theses are the mandatory headers required for ApteanPay Merchant API (GraphQL).

{
  "x-aptean-apim":"<<<your product specific apim key here>>>",
  "x-aptean-tenant":"<<<your tenant id here>>>",
  "x-aptean-tenant-secret": "<<<your tenant secret here>>>",
  "idempotency-key":"<<<your idempotency key goes here>>>"
}

Please fill your respective values appropriately to use them.

NOTE: idempotency-key is a unique value that must be provided to successfully create a payment.
This Unique value lives for 24 hours.
You can use any value for the idempotency-key, as long as it's unique.
Why idempotency key?
In error scenarios, retrying a payment and refund can lead to overcharging a payee or drawing too much from a merchant. In order to safeguard against these scenarios, you will use the "Idempotency-Key" key and unique value (generated by you) in the request header.

Create Payment

To Create a Payment, perform the following steps.

  1. Open your browser and navigate to https://stg.api.apteanpay.com/
  2. Get the http headers required from here.
  3. Paste the headers in the HTTP HEADERS tab.
  4. Copy below text including the brackets.

    mutation createPayment($input:CreatePaymentInput!){
        createPayment(input:$input){
            code
            message
            payment{
             id
             status
             pendingReasonCode
             failureReason
          }
        }
    }
  5. In the GraphQL Playground, paste copied text in query/mutation section.
  6. To create payment, copy below text including the brackets

    Use the parameter "immediateCapture" as true to capture the payment immediately or false to only create a pre-auth

    {
       "input": {
       "paymentMethodId": "<<<*payment method Id/token here-this is the value returned by Capture Credit Card or Bank SDK*>>>",
       "amount":<<amount in cents>>,
       "currency":"<<currency type here>>>",
       "immediateCapture":true,
       "riskMetadata":{
          "address": {
          "postalCode":"<<<postal code here>>>",
          "country":"<<<country here>>>"
          },
          "phone": {
            "countryCode":"<<<phone country here>>>",
            "number":"<<<phone number here>>>"
            },
          "lineItems":[]
        }
      }
    }
  7. In the GraphQL Playground, paste copied text in QUERY VARIABLES section.
  8. Now run the mutation.
  9. Once you see the response code as SUCCESS, you can get the Payment Id in the Id field of the response.

    Sample SUCCESS Response:

    {
      "data": {
        "createPayment": {
          "code": "SUCCESS",
          "message": "payment captured",
          "payment": {
           "id": "3dc14e58-7159-4e12-9c92-9603024c75f4",
           "status": "COMPLETED"
          }
       }	
      }
    }
    NOTE: In case your response code is not SUCCESS, refer below error cases.
    Error Message Error Reason
    Response not successful: Received status code 400 "x-aptean-apim" entered is not a valid apteanpay apim key or "x-aptean-tenant-secret" entered is not correct
    idempotency key has already been used, a unique key must be provided idempotency-key given has already been used in past 24 hours. It should be unique.
    idempotency key is required unique "idempotency-key" must be passed in HTTP HEADERS
    unable to create payment, payment method not found paymentMethodId provided is not found in paymentMethods()
    Expected payment amount does not match current amount amount provided should match the payment request amount
    Variable "$input" got invalid value "UbD" at "input.currency"; Value "UbD" does not exist in "CurrencyType" enum. Did you mean the enum value "USD" or "CAD"? currency should be CAD / USD